﻿using System;
using System.Collections.Generic;
using System.Web;
using MindTouch.Dream;
using MindTouch.Tasking;


namespace Morange.Async
{
    using Yield = IEnumerator<IYield>;
    /// <summary>
    /// Summary description for AsyncCoreResult
    /// </summary>
    public class AsyncCoreResult : IAsyncResult
    {
        public HttpContext context;
        public AsyncCallback cb;
        public CoroutineHandler<AsyncCoreResult, Result> process;
        private object extraData;
        static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        public Result result;

        public AsyncCoreResult(HttpContext context, AsyncCallback cb, CoroutineHandler<AsyncCoreResult, Result> process, object extraData)
        {
            this.context = context;
            this.cb = cb;
            this.process = process;
            this.extraData = extraData;
        }

        #region IAsyncResult Members

        public object AsyncState
        {
            get {
                return this.extraData;
            }
        }

        public System.Threading.WaitHandle AsyncWaitHandle
        {
            get {
                return null;
            }
        }

        public bool CompletedSynchronously
        {
            get {
                return false;
            }
        }

        public bool IsCompleted
        {
            get {
                log.Error("IsCompleted");
                if (this.result != null)
                {
                    return this.result.HasFinished;
                }
                return false;
            }
        }

        #endregion
    }

}

